<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        function getVal(key) {
            let arr2 = []
            let arr3 = []
            let localhref = "http://localhost:8080?id=10&name=zhangsan&class=box&money=99999"
            let arr = localhref.split("?")[1].split("&")
            arr.forEach(item => {
                arr2.push(item.split("="))
            })
            // console.log(arr2);
            arr2.forEach(item => {
                item.forEach(item => {
                    arr3.push(item)
                })
            })
            // console.log(arr3);
            let obj = {}
            for (let i = 0; i < arr3.length; i += 2) {
                obj[arr3[i]] = arr3[i + 1]
            }
            // for (let i in obj) {
            //     if (i == key) {
            //         return key = obj[i]
            //     }
            // }
            return obj[key]
        }
        console.log(getVal("id"));
    </script>
</body>

</html>